﻿@model IEnumerable<HotelManageSystem.Models.RoomInfoModel>
@{
    ViewBag.Title = "ShowRoomByState";
    Layout = "~/Views/Shared/_Template3.cshtml";
}
@section Head{
    <link href="../../Content/TelerikGrid.css" rel="stylesheet" type="text/css" />
    <script src="../../JS/popup.js" type="text/javascript"></script>
    <link href="../../Content/popup.css" rel="stylesheet" type="text/css" />
}
@{ Html.Telerik().Grid(Model)
    .Name("Grid")
    .DataKeys(key => key.Add(r => r.ID))
    .DataBinding(dataBind => dataBind.Ajax()
                                 .Select("TelerikAjax", "Room")
                                 )

    .Pageable(page => page
        .Style(GridPagerStyles.NextPreviousAndNumeric)
        .Position(GridPagerPosition.Bottom)
        .PageSize(12))

    .Columns(columns =>
                 {
                     columns.Bound(r => r.ID).Width(60).Title("客房编号").HtmlAttributes(new { style = "text-align: center" });
                     columns.Bound(r => r.Name).Width(40).Title("客房名").HtmlAttributes(new { style = "text-align: center" });
                     columns.Bound(r => r.BedNum).Width(40).Title("床数量").HtmlAttributes(new { style = "text-align: center" });
                     columns.Bound(r => r.FloorName).Width(40).Title("楼层").HtmlAttributes(new { style = "text-align: center" });
                     columns.Bound(r => r.RoomStateName).Width(40).Title("房态").HtmlAttributes(new { style = "text-align: center" });
                     columns.Bound(r => r.RoomTypeName).Width(80).Title("房间类型").HtmlAttributes(new { style = "text-align: center" });
                     if (Convert.ToInt32(Session["stateId"]) == 1)
                     {
                         columns.Template(r => @Html.Raw("<a id='" + r.ID + "' onclick='numberOfClient(event)'>入住…</a>"))
                                .ClientTemplate("<a id='<#=ID#>' onclick='numberOfClient(event)'>入住…</a>").Title("操作").Width(60);
                     }
                     if (Convert.ToInt32(Session["stateId"]) == 2)
                     {
                         columns.Template(r => @Html.Raw("<a id='" + r.ID + "' href='" + @Url.Content("../../ClientConsumption/SelectProduct/?roomId=" + r.ID) + "'>消费…</a>"))
                                .ClientTemplate("<a href='" + @Url.Content("../../ClientConsumption/SelectProduct/?roomId=<#= ID #>") + "'>消费…</a>").Title("消费").Width(60);
                         columns.Template(r => @Html.Raw("<a id='" + r.ID + "' href='" + @Url.Content("../../CheckOut/CheckOut/?roomId=" + r.ID) + "'>结账…</a>"))
                                .ClientTemplate("<a href='" + @Url.Content("../../CheckOut/CheckOut/?roomId=<#= ID #>") + "'>结账…</a>").Title("结账").Width(60);
                     }

                 })
     .Editable(e => e.Mode(GridEditMode.PopUp))
     .Selectable()
     .Sortable()
     .Filterable()
     .Scrollable(scrolling => scrolling.Height(400))
     .ClientEvents(c => c.OnDataBound("OnDataBound"))
     .Render();
}
<script type="text/javascript">
    //先将roomID载入
    $(function() {
        $("a").click(function() {
            roomID = $(this).attr("id");
            var empty = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            $("#rid").html("房间编号：" + roomID + empty);
        });
    });
    //再次加载时重新绑定
    function OnDataBound() {
        $("a").click(function () {
            roomID = $(this).attr("id");
            var empty = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            $("#rid").html("房间编号：" + roomID + empty);
        });
    }

</script>
